package test.instrumentation.classfiletest;

/**
 * @author tim
 * 
 *         This is an example of an approach to providing generic ability to provide the instrumentation content. Rather
 *         than having to deal with strings to compile new code. Use Annotations or an interface to define methods
 *         containing Java code that should be inserted into the appropriate place for
 */
public class AlternativeInstrumentationApproachAnnotations {

	/**
	 * indicates the contents of the annotated method should be injected before the instrumented method contents
	 */
	@interface Before {
	}

	/**
	 * indicates the contents of the annotated method should be injected after the instrumented method contents
	 */
	@interface After {
	}

	/**
	 * indicates the contents of the annotated method should be used to catch and then re-throw any exceptions from the
	 * instrumented method Suffers from limitation of how you pass in the Exception to the method...
	 */
	@interface Catch {
	}

	/**
	 * Indicates that the annotated field should be declared as a local variable within an instrumented method body.
	 */
	@interface Local {
	}

	/**
	 * Indicates that the annotated field should be declared as a new field within the instumented class.
	 */
	@interface Field {
	}

	@Before
	void logbefore() {
		startTime = System.currentTimeMillis();
		System.out.println("before");
	}

	@After
	void logafter() {
		final long elapsedTime = System.currentTimeMillis() - startTime;
		System.out.println("after. Elapsed: " + elapsedTime);
	}

	@Local
	long startTime;

}
